package com.sunlands.qdcy.tongzhuo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sunlands.qdcy.tongzhuo.model.DiaryDO;
import com.sunlands.qdcy.tongzhuo.model.UserDiaryReplyDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import javax.persistence.Id;
import java.util.Date;

/**
 * @date 2019/5/2914:21
 */
@Data
@JsonSerialize
@ApiModel(value = "转发评论到群")
@Builder
public class ForwardCommentVO {

    @Id
    @ApiModelProperty(value = "评论id")
    private Long commentId;

    @ApiModelProperty(value = "评论用户id")
    private Long commentUserId;

    @ApiModelProperty(value = "评论用户当前目标")
    private String commentTargetName;

    @ApiModelProperty(value = "评论用户昵称")
    private String commentUserName;

    @ApiModelProperty(value = "评论用户头像")
    private String commentUserAvatarUrl;

    @ApiModelProperty(value = "评论内容")
    private String commentContent;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "日记id")
    private Long diaryId;

    @ApiModelProperty(value = "日记用户id")
    private Long diaryUserId;

    @ApiModelProperty(value = "日记用户当前目标")
    private String diaryTargetName;

    @ApiModelProperty(value = "日记用户昵称")
    private String diaryUserName;

    @ApiModelProperty(value = "日记用户头像")
    private String diaryUserAvatarUrl;

    @ApiModelProperty(value = "日记内容")
    private String diaryContent;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date diaryCreateTime;

    @ApiModelProperty(value = "日记点赞数")
    private Integer zanDiaryCount;

    @ApiModelProperty(value = "日记回复数")
    private Integer diaryReplyCount;

    @ApiModelProperty(value = "日记转发次数")
    private Long diaryForwardCount;

    @ApiModelProperty(value = "日记图片内容，多个逗号分隔")
    private String imgUrls;

    public static ForwardCommentVO from(UserDiaryReplyDO diaryReply, DiaryDO userDiary) {
        if (null == userDiary || null == diaryReply) {
            return null;
        }
        return ForwardCommentVO.builder()
                .commentContent(diaryReply.getReplyContent())
                .commentId(diaryReply.getId())
                .commentUserId(diaryReply.getReplyUserId())
                .createTime(diaryReply.getCreateTime())
                .diaryContent(userDiary.getContent())
                .diaryCreateTime(userDiary.getCreateTime())
                .diaryId(userDiary.getId())
                .diaryUserId(userDiary.getUserId())
                .build();
    }

}
